<style>
.layui-table-cell {
/*    padding:0 5px;
    height:auto;*/
/*    overflow:visible;*/
/*    text-overflow:inherit;*/
/*    white-space:normal;	           
    word-break: break-all;*/
}
.blue{cursor: pointer;}
</style>
<table id="dataTable" lay-filter="demoEvent"></table>

{include file="system@block/layui" /}


<script type="text/html" id="subbtnTpl">
    {{# if(d.status==0){ }} 
        <a href="{:url('status')}?id={{ d.id }}" title="审核" class="blue hisi-ajax subbtn-{{ d.id }}" lay-event="handle1" confirm="该亏损物料是否已进行处理？">待处理</a>
    {{# }else{ }}
        已处理
    {{# } }}   
</script>
<script type="text/javascript">
    layui.use(['table', 'tool','jquery','layer'], function() {
        var $ = layui.jquery;
        var table = layui.table,layer=layui.layer;
        table.render({
            elem: '#dataTable'
            ,url: "{:url()}?order_id={:$orderId}" //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: false
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
                 ,{field:'create_time',title : '发现时间',templet:function(d){return layui.util.toDateString(d.create_time * 1000)},width:160}//
                ,{field:'name',title : '材料名称',templet:function(d){return d.omInfo.mInfo.name},width:100}
                ,{field:'sku',title : 'SKU',templet:function(d){return "<span class='copy-item'>"+d.omInfo.mInfo.material_sku+"</span>"},width:120}
                ,{field:'type',title : '工序',width:80}
                ,{field:'checkcloth_length',title : '验布米长',templet:function(d){return d.omInfo.checkcloth_length},width:90}
                ,{field:'shiji_weight_shrink',title : '缩水前净重量',templet:function(d){return d.omInfo.shiji_weight_shrink},width:100}
                ,{field:'billing_caigou_count',title : '开单采购总量',templet:function(d){return d.omInfo.billing_caigou_count},width:100}
                ,{field:'billing_caigou_kgcount',title : '开单采购公斤数',templet:function(d){return d.omInfo.billing_caigou_kgcount},width:110}
                ,{field:'caichuang_after',title : '裁后总长',templet:function(d){return d.caichuang_after},width:90}
                ,{field:'yingcai_count',title : '应裁数',templet:function(d){return d.omInfo.yingcai_count},width:80}
                ,{field:'shicai_count',title : '实裁数',templet:function(d){return d.shicai_count},width:80}
                ,{field:'weight',title : '客户克重',templet:function(d){return d.omInfo.weight},width:100}
                ,{field:'vWeight',title : '平均克重',templet:function(d){return d.vWeight.toFixed(2)},width:90}
                ,{field:'subbtn', title:'操作', templet:'#subbtnTpl',width:90}
                ,{field: 'remark', title: '备注',edit:'text',style:'border-bottom:2px dotted #5FB878;',width:100} 
            ]]
            ,done:function(res){
                table.on('edit(demoEvent)', function(obj){
                     var value = obj.value //得到修改后的值
                    ,d = obj.data //得到所在行所有键值
                    ,field = obj.field; //得到字段
                    // 编辑采购总金额
                    if (field == 'remark') {
                        $.ajax({
                           type: "POST",
                           url: "{:url('remark')}",
                           data: "id="+d.id+"&remark="+value,
                           dataType:"json",
                           success: function(res){
                              if (res.code == 1) {
                                 layer.msg(res.msg, {icon: 1});
                              } else {
                                 layer.msg(res.msg, {icon: 2,anim: 6});
                              }
                           }
                        });
                    }
                });
            }
        });
    });
</script>